<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">患者信息</block>
		</cu-custom>
		
		<view class="wrap" >
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#0081ff" ref="tabs" :list="list" :current="current" @change="change" :is-scroll="false"
				 swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<!-- 第一页 -->
				<swiper-item class="swiper-item">
					<scroll-view scroll-y style="height: 100%;width: 100%;">
						<!-- UI设计 -->
						<view class="cu-timeline">
							<view class="cu-time">
								<text class='cuIcon-selection text-white text-lg bg-blue round padding-xs'></text>
								<text class='text-xl margin-left'>患者信息</text>
							</view>
							<view class="cu-item text-blue" >
								<view class="content">
									<view class="cu-capsule radius"> 
									
									 <view class="text-container">
											<view>地址：{{patientInfo.address}}</view>
											<view>病床号：{{patientInfo.admission_no}}</view>
											<view>是否为农业户口：{{patientInfo.agricultural_indicator}}</view>
											<view>血压：{{patientInfo.blood_pressure}}</view>
											<view>合并疾病：{{patientInfo.comorbidity}}</view>
											<view>创建时间：{{patientInfo.create_time}}</view>
											<view>诊断结果：{{patientInfo.diagnosis}}</view>
											<view>教育程度：{{patientInfo.education_level}}</view>
											<view>紧急联系人：{{patientInfo.emergency_contact}}</view>
											<view>紧急联系人电话：{{patientInfo.emergency_contact_phone}}</view>
											<view>生育史：{{patientInfo.fertility_history}}</view>
											<view>性别：{{patientInfo.gender}}</view>
											<view>身份证号码及账号：{{patientInfo.identity_card}}</view>
											<view>婚姻状况：{{patientInfo.marital_status}}</view>
											<view>医疗费用承担方式：{{patientInfo.methods_of_medical_cost_coverage}}</view>
											<view>姓名：{{patientInfo.name}}</view>
											<view>职业：{{patientInfo.occupation}}</view>
											<view>电话：{{patientInfo.phone}}</view>
											<view>心率：{{patientInfo.pulse}}</view>
											<view>呼吸频率：{{patientInfo.respiration_rate}}</view>
											<view>体温：{{patientInfo.temperature}}</view>
											<view>治疗方式：{{patientInfo.therapeutic_modality}}</view>
											<view>更新时间：{{patientInfo.update_time}}</view>
									</view>
									
									 </view>

								
								</view>
							</view>
							<view class="cu-item text-blue" >
								<view class="content">
									<view class="cu-capsule radius"> 
									
									 <view class="text-container">
											
						<view>应激感受量表评分:{{xinlipingfeninfo[3]}}           </view>
						<view>                                                  </view>
						<view>广泛性焦虑量表评分:{{xinlipingfeninfo[5]}}         </view>
						<view>                                                  </view>
						<view>宾州担忧问卷:{{xinlipingfeninfo[7]}}               </view>
						<view>                                                  </view>
						<view>患者健康问卷抑郁量表评分:{{xinlipingfeninfo[9]}}    </view>
						<view>                                                  </view>
						<view>反刍思维量表评分:{{xinlipingfeninfo[11]}}          </view>
						<view>                                                  </view>
						<view>前瞻回溯记忆问卷:{{xinlipingfeninfo[13]}}          </view>
						<view>                                                  </view>
						<view>生命质量核心量表:{{xinlipingfeninfo[15]}}          </view>
						<view>                                                  </view>
						<view>匹兹堡睡眠质量指数:{{xinlipingfeninfo[17]}}        </view>
									</view>                                    
									
									 </view>
							
								
								</view>
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>


export default {
	data() {
		return {
			xinlipingfeninfo:[],
			userinfo:{},
			show: 1,
			current: 0,
			list: [{
					name: '患者信息'
				}
			],
			swiperCurrent: 0,
			dx: 0,
			patientInfo: []
		};
	},
	onLoad(option) {
		this.userinfo=uni.getStorageSync("userinfo")
		
		this.xinlipingfen(option.userid)
		this.fetchPatientInfo(option.identity_card); // 假设这里传递身份证号
	},
	methods: {
		xinlipingfen(userid){
			
			// 发送 GET 请求
			uni.request({
			    url: `http://202.127.200.31:30010/user/users/${userid}`,
			    method: 'GET',
			    success: (res) => {
			        if (res.statusCode === 200 && res.data && Array.isArray(res.data["psychological_records"]) && res.data["psychological_records"].length > 0) {
			            console.log('获取成功:', res.data["psychological_records"]);
			            this.xinlipingfeninfo = res.data["psychological_records"][0];
			
			            uni.showToast({
			                title: '获取成功',
			                icon: 'success',
			                duration: 2000
			            });
			        } else {
			            console.log('数据不符合预期:', res.data);
			            uni.showToast({
			                title: '数据错误',
			                icon: 'none',
			                duration: 2000
			            });
			        }
			    },
			    fail: (err) => {
			        console.error('获取失败:', err);
			        uni.showToast({
			            title: '请求失败',
			            icon: 'none',
			            duration: 2000
			        });
			    }
			});
		},
		// tab栏切换
		change(index) {
			this.swiperCurrent = index;
		},
		transition({
			detail: {
				dx
			}
		}) {
			this.$refs.tabs.setDx(dx);
		},
		animationfinish({
			detail: {
				current
			}
		}) {
			this.$refs.tabs.setFinishCurrent(current);
			this.swiperCurrent = current;
			this.current = current;
		},
		fetchPatientInfo(identityCard) {
			
			uni.request({
			    url: 'http://202.127.200.31:30010/user/list',
			    method: 'POST',
			    data: {
			        identity_card: identityCard // 确保这个变量已经在上下文中正确定义
			    },
			    header: {
			        'Content-Type': 'application/json' // 对于POST请求，通常发送JSON格式的数据
			    },
			    success: (res) => {
			        console.log('查询成功:', res.data);
			        if (res.statusCode === 200) { // 确保HTTP状态码为200
			            if (res.data.code === 20000) {
			                this.patientInfo = res.data.data; // 更新组件中的数据
			            } else {
			                console.error('查询失败:', res.data.message);
			            }
			        } else {
			            console.error('服务器响应错误:', res.statusCode);
			            uni.showToast({
			                title: '服务器错误',
			                icon: 'none'
			            });
			        }
			    },
			    fail: (err) => {
			        console.error('查询失败:', err);
			        uni.showToast({
			            title: '请求失败',
			            icon: 'none'
			        });
			    }
			});
				
		}
	}
};
</script>

<style lang="scss" scoped>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.cu-timeline .cu-time {
		width: 100%;
		text-align: left;
		padding: 20rpx 0 20rpx 37rpx;
		font-size: 26rpx;
		color: #888;
		display: block;
	}

	.text-red,
	.line-red,
	.lines-red {
		color: #FF3434;
	}

	.margin-avatar {
		margin-left: -15rpx;
	}

	.margin-avatar-bottom {
		margin-bottom: 150rpx;
	}

	.line-blue-tuniao::after {
		border-color: #0070ff !important;
		color: #0070ff;
	}

	.resume {
		/* background: #f1f1f1; */
		padding-top: 10rpx;
		border-radius: 6rpx;
		display: block;
		color: #666;
		line-height: 1.6;
	}

	.resume+.resume {
		margin-top: 20rpx;
	}

	.resume2 {
		padding-top: 10rpx;
		border-radius: 6rpx;
		display: block;
		color: #666;
		line-height: 1.6;
	}

	.edit {
		position: fixed;
		width: 100rpx;
		height: 100rpx;
		bottom: 250rpx;
		right: 30rpx;
		z-index: 1;
		opacity: 0.8;
		border: 1px solid #189eff;
		border-radius: 100rpx;
		box-shadow: 0rpx 0rpx 6rpx rgba(24, 158, 255, 1);
		padding: 20rpx;
	}

	.love {
		position: fixed;
		width: 100rpx;
		height: 100rpx;
		bottom: 550rpx;
		right: 30rpx;
		z-index: 1024;
		opacity: 0.8;
		border: 1px solid #189eff;
		border-radius: 100rpx;
		box-shadow: 0rpx 0rpx 6rpx rgba(24, 158, 255, 1);
		padding: 20rpx;
	}

	.bg-img-cont {
		background-size: cover;
		background-position: center;
		background-repeat: no-repeat;
		height: 350rpx;
	}

	.share-png {
		width: 100rpx;
		height: 100rpx;
		margin: 0 auto;
	}

	.share-wechat {
		width: 35rpx;
		height: 35rpx;
		margin: 0 10rpx -4rpx 0;
		opacity: 0.5;
	}

	.button-no::after {
		border: none;
	}

	.title-pyq {
		background-image: -webkit-linear-gradient(0deg, #1b6cff, #1ca5ff);
		/*1B6CFF 1B42FF*/
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		opacity: 0.5;
	}

	.edit-fixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 1024;
		box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0.1);
	}

	.button-no {
		border: none;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0);
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 300rpx;
			border-radius: 50%;
			margin: 0 auto;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, #1cbbb4 0%, #0081ff 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
</style>